﻿using DemoQLKhoSX.DatabaseAccessLayer;
using DemoQLKhoSX.EntityClasses;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace DemoQLKhoSX.BusinessLogicLayer
{
    public class KhachHangBLO
    {
        private KhachHangDAO _KhachHangDAO;

        public KhachHangBLO()
        {
            _KhachHangDAO = new KhachHangDAO();
        }

        public KhachHangEntity getKhachHangByID(string id)
        {
            KhachHangEntity KhachHang = new KhachHangEntity();
            DataTable tbl = new DataTable();
            tbl = _KhachHangDAO.searchByID(id);

            if (tbl != null)
                foreach (DataRow r in tbl.Rows)
                {
                    KhachHang.IDKhachHang = id;
                    KhachHang.DiaChi = r["DiaChi"].ToString();
                    KhachHang.SoDT = r["SoDT"].ToString();
                    KhachHang.SoTK = r["SoTK"].ToString();
                    KhachHang.TenKH = r["TenKH"].ToString();
                }
            return KhachHang;
        }

        public List<KhachHangEntity> getKhachHang()
        {
            List<KhachHangEntity> KhachHang = new List<KhachHangEntity>();
            DataTable tbl = new DataTable();
            tbl = _KhachHangDAO.searchByID("");

            if (tbl != null)
                foreach (DataRow r in tbl.Rows)
                {
                    KhachHangEntity nKhach = new KhachHangEntity();
                    nKhach.IDKhachHang = r["IDKhachHang"].ToString();
                    nKhach.DiaChi = r["DiaChi"].ToString();
                    nKhach.SoDT = r["SoDT"].ToString();
                    nKhach.SoTK = r["SoTK"].ToString();
                    nKhach.TenKH = r["TenKH"].ToString();
                    KhachHang.Add(nKhach);
                }
            return KhachHang;
        }

        public bool ThemKH(string id, string tenkh, string sodt, string sotk, string diachi)
        {
            bool a = false;
            a = _KhachHangDAO.ThemKhachHang(id, tenkh, sodt, sotk, diachi);
            return a;
        }
    }
}
